import request from "@/utils/request";

// const AUTH_BASE_URL = "/api/v1/auth";
const AUTH_BASE_URL = "/admin/auth";
const AuthAPI = {
  /** 登录接口*/
  login(data) {
    // const formData = new FormData();
    // formData.append("username", data.username);
    // formData.append("password", data.password);
    //formData.append("captchaKey", data.captchaKey);
    //formData.append("captchaCode", data.captchaCode);
    return request({
      url: `${AUTH_BASE_URL}/login`,
      method: "post",
      // data: formData,
      data:{"username":data.username,"password":data.password},
      // headers: {
      //   "Content-Type": "multipart/form-data",
      // },
    });
  },

  /** 刷新 token 接口*/
  // refreshToken(refreshToken) {
  //   return request({
  //     url: `${AUTH_BASE_URL}/refresh-token`,
  //     method: "post",
  //     params: { refreshToken: refreshToken },
  //     headers: {
  //       Authorization: "no-auth",
  //     },
  //   });
  // },

  /** 刷新 token 接口*/
refreshToken(refreshToken) {
  return request({
    url: `${AUTH_BASE_URL}/refreshToken`, //  注意：路径名与后端一致（驼峰）
    method: "post",
    data: { refreshToken: refreshToken }, // 使用 JSON body 传参
    headers: {
      Authorization: "no-auth",
    },
  });
},


  /** 注销登录接口 */
  logout() {
    return request({
      url: `${AUTH_BASE_URL}/logout`,
      method: "get",
    });
  },

  /** 获取验证码接口*/
  getCaptcha() {
    return request({
      url: `${AUTH_BASE_URL}/captcha`,
      method: "get",
    });
  },
};

export default AuthAPI; 